package cn.lds.healthexamspringboot.interceptor;

import cn.lds.healthexamspringboot.domain.User;
import cn.lds.healthexamspringboot.dto.HealthExamConstant;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 医生权限拦截器
 */
@Component
public class DoctorAuthInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        HttpSession session = request.getSession();

        User loginUser = (User) session.getAttribute("login");

        if (!loginUser.getRoleId().equals(2)){
            request.setAttribute("err", "您的权限不能访问改页面");
            request.getRequestDispatcher("/go_403").forward(request,response);
        }





        return true;

    }
}
